package com.yyk.yykywd.ui.customer;

import android.widget.TextView;

import com.orhanobut.hawk.Hawk;
import com.orhanobut.logger.Logger;
import com.yyk.yykywd.R;
import com.yyk.yykywd.base.BaseActivity;
import com.yyk.yykywd.http.ApiService;
import com.yyk.yykywd.bean.ClentClientReturneddetailInfo;
import com.yyk.yykywd.util.Md5Util2;

import java.util.Map;
import java.util.TreeMap;

import butterknife.BindView;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * 查看回款信息
 */
public class QueryHuikuanActivity extends BaseActivity {


    @BindView(R.id.tv_classes)
    TextView tvClasses;
    @BindView(R.id.tv_money)
    TextView tvMoney;
    @BindView(R.id.tv_pay_money)
    TextView tvPayMoney;

    @BindView(R.id.tv_remark)
    TextView tvRemark;
    private String id;

    @Override
    public int getLayoutId() {
        return R.layout.activity_query_huikuan;
    }

    @Override
    public void initView() {
        setBackArrow();
        setTitle("回款信息");
    }

    @Override
    public void initData() {
        id = getBundle().getString("id");
        postClentClientReturneddetail();

    }

    /**
     * 接口33:回款信息详情（whm）
     */
    private void postClentClientReturneddetail() {
        Map<String, String> map = new TreeMap<>();
        map.put("uid", Hawk.get("uid") + "");
        map.put("bid", id + "");
        map.put("sign", Md5Util2.createSign(map));
        ApiService.getInstance().api.postClentClientReturneddetail(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new Observer<ClentClientReturneddetailInfo>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ClentClientReturneddetailInfo info) {
                        Logger.e("33回款信息详情" + info.toString());
                        if (info.getCode() == 1) {
                            float money = info.getData().getMoney();
                            String remark = info.getData().getRemark();
                            float pay_money = info.getData().getPay_money();
                            int classes = info.getData().getClasses();
                            tvMoney.setText(money + "");
                            tvPayMoney.setText(pay_money + "");
                            tvRemark.setText(remark + "");
                            if (classes == 1) {
                                tvClasses.setText("全部回款");
                            } else if (classes == 2) {
                                tvClasses.setText("部分回款");
                            } else {
                                tvClasses.setText("不用回款");
                            }
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        Logger.t("异常" + e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }


}
